home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 004 / bm / movresidue.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  1KB  |  38 lines

  1. #include "bm.h"
  2. /* Moves the text which has not been completely searched at the end of
  3. * the buffer to the beginning of the buffer
  4. * and returns number of bytes moved */
  5. int MoveResidue(DescVec, NPats,Buffer, BuffEnd)
  6. struct PattDesc *DescVec[];
  7. int NPats;
  8. char *Buffer, *BuffEnd;
  9. {
  10.     char *FirstStart, *f, *t, *Residue;
  11.     int ResSize, i;
  12.     FirstStart = BuffEnd;
  13.     /* find the earliest point which has not been
  14.     * completely searched */
  15.     for (i=0; i < NPats; i++) {
  16.         FirstStart = 
  17.             min(FirstStart, DescVec[i]-> Start );
  18.     } /* for */
  19.     /* now scan to the beginning of the line containing the
  20.     * unsearched text */
  21.     for (Residue = FirstStart; *Residue != '\n' &&
  22.     Residue >= Buffer; Residue--);
  23.     if (Residue < Buffer)
  24.         Residue = FirstStart;
  25.     else ++Residue;
  26.     ResSize = (BuffEnd - Residue + 1);
  27.     /* now move the residue to the beginning of
  28.     * the file */
  29.     t = Buffer; f = Residue;
  30.     for(i=ResSize;i;--i)
  31.         *t++ = *f++;
  32.     /* now fix the status vectors */
  33.     for (i=0; i < NPats; i++) {
  34.         DescVec[i]->Start -= (Residue - Buffer);
  35.     } /* for */
  36.     return(ResSize);
  37. } /* MoveResidue */
  38.